package com.publicize.commom.servicebase.handler;

import com.publicize.commom.commonutils.ExceptionUtil;
import com.publicize.commom.commonutils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public Result error(Exception e){
        log.error(ExceptionUtil.getMessage(e));
        return Result.error().message(e.getMessage());
    }
    @ExceptionHandler(com.publicize.commom.servicebase.exception.MyException.class)
    public Result error(com.publicize.commom.servicebase.exception.MyException e){
        log.error(ExceptionUtil.getMessage(e));
        return Result.error().message(e.getMsg()).code(e.getCode());
    }
    @ExceptionHandler(IllegalArgumentException.class)
    public Result handler(IllegalArgumentException e){
        return null;
    }
}
